package com.terrace.db.system.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.terrace.db.constant.DBType;
import com.terrace.db.system.dao.DataSourceDao;
import com.terrace.db.system.mapper.entity.DataSource;
import com.terrace.db.system.service.DataSourceService;
import com.terrace.core.mybatis.entity.Pagination;
import com.terrace.core.mybatis.plugin.pagination.PaginationHelper;

@Service
@Transactional
@com.terrace.core.spring.datasource.annotation.DataSource(name = DBType.ADMIN)
public class DataSourceServiceImpl implements DataSourceService {

	@Autowired
	private DataSourceDao dataSourceDao;
	
	@Override
	public int insertDataSourceSelective(DataSource dataSource) {
		return dataSourceDao.insertDataSourceSelective(dataSource);
	}

	@Override
	public int deleteDataSourceByName(String dbName) {
		return dataSourceDao.deleteDataSourceByName(dbName);
	}

	@Override
	public int updateDataSourceByNameSelective(DataSource dataSource) {
		return dataSourceDao.updateDataSourceByNameSelective(dataSource);
	}

	@Override
	public DataSource selectDataSourceByName(String dbName) {
		return dataSourceDao.selectDataSourceByName(dbName);
	}

	@Override
	public Pagination<DataSource> selectDataSourceForPagination(Pagination<DataSource> pagination, DataSource dataSource) {
		PaginationHelper.prepare(pagination);
		return PaginationHelper.execute(dataSourceDao.selectDataSourceForPagination(dataSource));
	}

}
